/*******************************************************************************

Master file for Race to the Bottom: Competition and Quality in Science
Quarterly Journal of Economics, 2025

Ryan Hill: ryan.hill@kellogg.northwestern.edu
Carolyn Stein: carolyn_stein@berkeley.edu
Last modified: January 2025

*******************************************************************************/

clear all
set more off, permanently
macro drop _all
set seed 1991
version 16

/*------------------------------------------------------------------------------

	PACKAGES (uncomment any you may need to install)

------------------------------------------------------------------------------*/	

/*
ssc install binscatter
ssc install gtools
ssc install ivreg2
ssc install weakivtest
ssc install avar
ssc install strgroup
ssc install winsor2
ssc install regsave
ssc install ranktest
ssc install egenmore
net install grc1leg, from(http://www.stata.com/users/vwiggins/)
net install lassopack, from(https://raw.githubusercontent.com/statalasso/lassopack/master/lassopack_v13) replace
net install scheme-modern, from(https://raw.githubusercontent.com/mdroste/stata-scheme-modern/master/)
*/

/*------------------------------------------------------------------------------

	GLOBALS

------------------------------------------------------------------------------*/

* INSERT USER ROOT HERE
global user_root		// your file path here

* Folders
global data_raw			"${user_root}Data/01_Raw/"
global data_clean		"${user_root}Data/02_Clean/"
global data_built		"${user_root}Data/03_Built/"

global code_clean		"${user_root}Code/01_Clean/"
global code_build  		"${user_root}Code/02_Build/"
global code_analysis	"${user_root}Code/03_Analysis/"

global figures          "${user_root}Figures/"
global tables           "${user_root}Tables/"

* Controls
global time_controls i.depositionYear
global complexity_controls lnStructureMolecularWt lnStructureMolecularWt2 	///
lnResidueCount lnResidueCount2 lnAtomSiteCount lnAtomSiteCount2

* Graph format
set scheme modern


/*------------------------------------------------------------------------------

	SWITCHES (set any files you want to run to 1)

------------------------------------------------------------------------------*/

** CLEAN ***********************************************************************

local switch_clean_summary				= 1
local switch_clean_citation				= 1
local switch_clean_refine				= 1
local switch_clean_collection			= 1
local switch_clean_entity				= 1
local switch_clean_pubmed				= 1	
local switch_clean_validation			= 1
local switch_clean_drugbank				= 1
local switch_clean_survey				= 1

** BUILD ***********************************************************************

local switch_build_pdb					= 1
local switch_build_entities				= 1
local switch_build_structures			= 1
local switch_build_papers				= 1
local switch_define_sample				= 1
local switch_generate_p					= 0 // requires restricted data

** ANALYSIS ********************************************************************

local switch_summary_stats          	= 1
local switch_potential_regressions		= 1
local switch_structural_genomics		= 1
local switch_competition_regressions	= 1
local switch_welfare					= 1
local switch_welfare_calculations		= 1
local switch_appendix_misc         		= 1
local switch_phat_bootstrap				= 0 // requires restricted data
local switch_survey_analysis			= 1


/*------------------------------------------------------------------------------

	EXECUTION

------------------------------------------------------------------------------*/

** CLEAN ***********************************************************************

if `switch_clean_summary' == 1 {
	do "${code_clean}01_clean_summary.do"
	}
	
if `switch_clean_citation' == 1 {
	do "${code_clean}02_clean_citation.do"
	}
	
if `switch_clean_refine' == 1 {
	do "${code_clean}03_clean_refine.do"
	}
	
if `switch_clean_collection' == 1 {
	do "${code_clean}04_clean_collection.do"
	}
	
if `switch_clean_entity' == 1 {
	do "${code_clean}05_clean_entity.do"
	}
	
if `switch_clean_pubmed' == 1 {
	do "${code_clean}06_clean_pubmed.do"
	}
	
if `switch_clean_validation' == 1 {
	do "${code_clean}07_clean_validation.do"
	}
	
if `switch_clean_drugbank' == 1 {
	do "${code_clean}08_clean_drugbank.do"
	}
	
if `switch_clean_survey' == 1 {
	do "${code_clean}09_clean_survey.do"
	}

** BUILD ***********************************************************************

if `switch_build_pdb' == 1 {
	do "${code_build}01_build_pdb.do"
	}
	
if `switch_build_entities' == 1 {
	do "${code_build}02_build_entities.do"
	}
	
if `switch_build_structures' == 1 {
	do "${code_build}03_build_structures.do"
	}
	
if `switch_build_papers' == 1 {
	do "${code_build}04_build_papers.do"
	}
	
if `switch_define_sample' == 1 {
	do "${code_build}05_define_sample.do"
	}
	
if `switch_generate_p' == 1 {
	do "${code_build}06_generate_p.do"
	}

** ANALYSIS ********************************************************************

if `switch_summary_stats' == 1 {
	do "${code_analysis}01_summary_stats.do"
}

if `switch_potential_regressions' == 1 {
	do "${code_analysis}02_potential_regressions.do"
}

if `switch_structural_genomics' == 1 {
	do "${code_analysis}03_structural_genomics.do"
}

if `switch_competition_regressions' == 1 {
	do "${code_analysis}04_competition_regressions.do"
}

if `switch_welfare' == 1 {
	do "${code_analysis}05_welfare.do"
}

if `switch_welfare_calculations' == 1 {
	do "${code_analysis}06_welfare_calculations.do"
}

if `switch_appendix_misc' == 1 {
	do "${code_analysis}07_appendix_misc.do"
}

if `switch_phat_bootstrap' == 1 {
	do "${code_analysis}08_phat_bootstrap.do"
}

if `switch_survey_analysis' == 1 {
	do "${code_analysis}09_survey_analysis.do"
}


